natural_number(0).
natural_number(s(X)) :- natural_number(X).

my_plus(0,X,X) :- natural_number(X).
my_plus(s(X),Y,s(Z)) :- my_plus(X,Y,Z).

my_member(X,[X|_]).
my_member(X,[_|Y]) :- my_member(X,Y).

my_append([],L,L).
my_append([H|T],L,[H|R]) :- my_append(T,L,R).

my_reverse([],[]).
my_reverse([H|T],R) :- my_reverse(T,W), my_append(W,[H],R).

a_reverse(Xs,Ys) :- a_reverse(Xs,[],Ys).
a_reverse([],Acc,Acc).
a_reverse([X|Xs],Acc,Ys) :- a_reverse(Xs,[X|Acc],Ys).


b_reverse(Xs,Ys) :- b_reverse(Xs, [], Ys).
b_reverse([],Acc,Acc).
b_reverse([X|Xs],Acc,Ys) :- b_reverse(Xs,[X|Acc],Ys).

%my_factorial(+N,-F)
my_factorial(N,F) :- my_factorial(N,F,1).
my_factorial(0,F,F).
my_factorial(N,F,F1) :-
    N > 0,
    N1 is N - 1,
    F2 is N * F1,
    my_factorial(N1, F, F2).



append_dl(A-B,B-C,A-C).
dl_append(A-B,B-C,A-C).


top(X,Y) :- p(X,Y).
top(X,X) :- s(X).

p(X,Y) :- my_true(1), q(X), !, r(Y).
p(X,Y) :- s(X), r(Y).

q(a). q(b). r(c). r(d). s(e).
my_true(X).

sentence -->  noun_phrase,verb_phrase.
noun_phrase --> [the],noun.
verb_phrase --> [runs].
noun --> [rabbit].
noun --> [engine].


